	<?php
		require("../sql/Database.php");
		$bdd = new Database();
	?>
	
	<?php
		// Deconnexion
		if ((isset($_GET['action'])) && ($_GET['action'] == 'logout')) {
				$_SESSION = array();
				session_destroy();
		}
	?>
	
	<?php
	 	// Champs non remplis
		if (!isset($_POST['password']) && !isset($_POST['login'])){ 
	?>
		<form action="administrator.php" method="post">
			<div class="login">
				<h2>
					Connexion
				</h2>
				Login<input type="text" name="login"/>
				Mot de passe<input type="password" name="password" />
				<input type="submit" value="Valider" />
			</div>
		</form>
	
	<?php
		// Champs remplis
	 	} else { 
			
			$getUser = $bdd->db_getUser($_POST['login'], $_POST['password']);
			$realPassword  = $getUser->password;
			
		
			// Verification
			if ($_POST['password'] != $realPassword) { 
		
	?>
		<form action="administrator.php" method="post">
			<div class="login">
				<h2>
					Connexion
				</h2>
				Login<input type="text" name="login"/>
				Mot de passe<input type="password" name="password" />
				<input type="submit" value="Valider" />
				<div class="error_form">Mot de passe incorrect</div>
			</div>
		</form>
	
	<?php } else {
		
			// Recuperation des informations de l'administrateur
			$_SESSION['uid'] = $getUser->uid;
			$_SESSION['name'] = $getUser->name;
			$_SESSION['login'] = $getUser->login;
			$_SESSION['password'] = $getUser->password;
	
			include("interface.php");
		} 
	}
	
?>